package com.example.computer_component_manager.activity

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.viewpager.widget.ViewPager
import com.example.computer_component_manager.R
import com.example.computer_component_manager.databinding.AboutBinding
import com.example.computer_component_manager.databinding.ActivityMenuBinding
import com.example.computer_component_manager.ui.main.SectionsPagerAdapter
import com.example.computer_component_manager.util.DbUtil

/**
 * 菜单界面
 *
 * @author 1923111015董寺卓
 */

class MenuActivity : AppCompatActivity() {

    companion object {

        var instance: MenuActivity? = null

    }

    private lateinit var binding: ActivityMenuBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityMenuBinding.inflate(layoutInflater)
        setContentView(binding.root)
        instance = this
        val viewPager: ViewPager = binding.viewPager
        // 新建一个TabSectionAdapter（继承FragmentPagerAdapter）变量
        // 将变量传给viewPager
        viewPager.adapter = SectionsPagerAdapter(this, supportFragmentManager)
        // tabLayout使用viewPager接收的tabSectionAdapter里设置的title
        binding.tabs.setupWithViewPager(viewPager)
        binding.tvMyName.text = DbUtil.loginAdminUserInfo?.name
        binding.tvMyName.setOnClickListener {
            val intent = Intent(this, ShowMineActivity::class.java)
            this.startActivity(intent)
        }
        binding.tvMenuTitle.setOnClickListener {
            AlertDialog.Builder(this).setTitle(resources.getString(R.string.about))
                .setView(AboutBinding.inflate(layoutInflater).root)
                .setPositiveButton(resources.getString(R.string.ok)) { _, _ -> }.show()
        }
    }

}